FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y curl wget && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 创建安装目录
ENV INSTALL_DIR=/opt
WORKDIR $INSTALL_DIR

# 添加JDK到镜像中
COPY jdk-8u162-linux-x64.tar.gz .
RUN tar -zxf jdk-8u162-linux-x64.tar.gz -C $INSTALL_DIR && \
    rm jdk-8u162-linux-x64.tar.gz && \
    mv $INSTALL_DIR/jdk1.8.0_162 $INSTALL_DIR/jdk

# 设置JAVA_HOME环境变量
ENV JAVA_HOME=${INSTALL_DIR}/jdk
ENV PATH=$JAVA_HOME/bin:$PATH
ENV CLASSPATH=$JAVA_HOME/jre/bin:$PATH

# 添加Tomcat到镜像中
COPY apache-tomcat-8.5.99.tar.gz .
RUN tar -zxf apache-tomcat-8.5.99.tar.gz -C $INSTALL_DIR && \
    rm apache-tomcat-8.5.99.tar.gz && \
    mv ${INSTALL_DIR}/apache-tomcat-8.5.99 ${INSTALL_DIR}/tomcat

# 配置Tomcat用户权限
RUN groupadd -r tomcat && useradd -r -g tomcat -d $INSTALL_DIR/tomcat -s /sbin/nologin tomcat && \
    chown -R tomcat:tomcat $INSTALL_DIR/tomcat

# 暴露8080端口，这是Tomcat默认的服务端口
EXPOSE 8080

# 启动Tomcat服务
USER tomcat
CMD ["sh", "-c", "$INSTALL_DIR/tomcat/bin/catalina.sh run"]


